/************************************

This file creates a version of results focused on aggregated hypotheses for effects
that are mirrored by party (collapsed version)

In this framework - test for robustness to multiple hypothesis testing
using List, Shaikh, and Vayalinkal (2023) bootstrap methods

Create a table with the results - one table for each decomposition method

*************************
Persuasion Decomposition:

Anonymous Message Hypotheses:
1. Hypothesis 1: Individuals are not moved by a message aligned with their party
2. Hypothesis 2: Individuals are not moved by a message that opposes their party

Persuasion Hypotheses: 
3. Hypothesis 3: Individuals are not moved by their party president source, 
				 conditional on a message that aligns with their party
4. Hypothesis 4: Individuals are not moved by their party president source, 
				 conditional on a message that opposes their party
5. Hypothesis 5: Individuals are not moved by the opposing party president source, 
				 conditional on a message that aligns with their party
6. Hypothesis 6: Individuals are not moved by the opposing party president source, 
				 conditional on a message that opposes their party

*************************
Alternative Decomposition for Priming:

Priming Hypotheses:
1. Hypothesis 1: Individuals are not primed by their party president source
2. Hypothesis 2: Individuals are not primed by the opposing party president source

Identified Message Hypotheses: 
3. Hypothesis 3: Individuals are not moved by a message that aligns with their party, 
				 conditional on their party president source
4. Hypothesis 4: Individuals are not moved by a message that opposes their party, 
				 conditional on their party president source
5. Hypothesis 5: Individuals are not moved by a message that aligns with their party, 
				 conditional on the opposing party president source
6. Hypothesis 6: Individuals are not moved by a message that opposes their party, 
				 conditional on the opposing party president source

************************************/


clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==0  {
cap cd "E:\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
} 

use 3_clean_data, replace

*Run Switch*
global run 0

***********************
*Create Log File*

cap log close

log using 14_MultipleHypothesisTesting.log, replace

*********************
*Globals for Controls*

local lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal tax_toohigh health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 
	
// need to generate dummies manually
gen freq_nytimes_0 = (freq_nytimes == 0)
gen freq_nytimes_1 = (freq_nytimes == 1)
gen freq_nytimes_2 = (freq_nytimes == 2)
gen freq_nytimes_3 = (freq_nytimes == 3)

gen freq_fox_0 = (freq_fox == 0)
gen freq_fox_1 = (freq_fox == 1)
gen freq_fox_2 = (freq_fox == 2)
gen freq_fox_3 = (freq_fox == 3)

local lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt ///
	freq_nytimes_0 freq_nytimes_1 freq_nytimes_2 freq_nytimes_3 ///
	daily_tv occ_tv daily_newspaper ///
	freq_fox_0 freq_fox_1 freq_fox_2 freq_fox_3 ///
	week_breitbart daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 
	
local alllasso `lasso0' `lasso1'

********************************************************************************
********************************Persuassion Result******************************

preserve

*generating outcome
gen ln_conv=ln1_prob_index_pro if treat!=0 & treat<5
replace ln_conv=ln1_prob_index_anti if treat>4 & treat<9

* generating treatments
gen ownpresident_against 	=   (treatment==6 &  recruit==1) /// D: Obama Anti
						   	  | (treatment==1 &  recruit==0) //  R: Trump Pro
gen ownactor_against 		=   (treatment==8 &  recruit==1) /// D: Obama Anti (Actor)
							  | (treatment==3 &  recruit==0) //  R: Trump Pro (Actor)
gen ownpresident_along 		=   (treatment==2 &  recruit==1) /// D: Obama Pro
							  | (treatment==5 &  recruit==0) //  R: Trump Anti
gen ownactor_along 			=   (treatment==4 &  recruit==1) /// D: Obama Pro (Actor)
							  | (treatment==7 &  recruit==0) //	 R: Trump Anti (Actor)
gen opppresident_against 	= 	(treatment==5 &  recruit==1) /// D: Trump Anti
							  | (treatment==2 &  recruit==0) //  R: Obama Pro
gen oppactor_against 		= 	(treatment==7 &  recruit==1) /// D: Trump Anti (Actor)
							  | (treatment==4 &  recruit==0) //  R: Obama Pro (Actor)
gen opppresident_along 		=   (treatment==1 &  recruit==1) /// D: Trump Pro
							  | (treatment==6 &  recruit==0) //  R: Obama Anti
gen oppactor_along 			=   (treatment==3 &  recruit==1) /// D: Trump Pro (Actor)
							  | (treatment==8 &  recruit==0) //  R: Obama Anti (Actor)

gen treatment_conv = ownactor_against + 2*ownactor_along + 3*oppactor_against + 4*oppactor_along ///
+ 5*ownpresident_against + 6*ownpresident_along + 7*opppresident_against + 8*opppresident_along
replace treatment_conv = . if treatment_conv == 0
replace treatment_conv = treatment_conv-1

drop if treatment_conv == .
/*
* we want to compare:
* 0 vs 4 - ownactor_against vs ownpresident_against - (4th pairwise combination)
* 1 vs 5 - ownactor_along vs ownpresident_along - (11th)
* 2 vs 6 - oppactor_against vs opppresident_against - (17th)
* 3 vs 7 - oppactor_along vs opppresident_along - (22nd)
*/

mata: conv_decomp2persuasion = (1,1,4\1,1,11\1,1,17\1,1,22)

if $run ==1 {
mhtexp2 ln_conv, treatment(treatment_conv) bootstrap(3000) combo("pairwise") only("conv_decomp2persuasion") controls(`alllasso' )
}

*Command Does Not Auto-save Estimates*
*Manually Enter as Globals*
*Use P-Values from Remark3_8 in paper*
*Own Message, Own President - r2 *
global coeff1_h3="-0.0045"
global p1_h3="0.526"
global star1_h3 ""
sum ln_conv if treatment_conv==1 
global y1_h3 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h3=`x'
count if treatment_conv==1 | treatment_conv==5
global n1_h3=`r(N)'

*Opp Message, Own President - r1 *
global coeff1_h4="0.0149"
global p1_h4="0.0237"
global star1_h4 "**"
sum ln_conv if treatment_conv==0 
global y1_h4 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h4=`x'
count if treatment_conv==0 | treatment_conv==4
global n1_h4=`r(N)'

*Own Message, Opp President - r4 *
global coeff1_h5="-0.0078"
global p1_h5="0.2756"
global star1_h5 ""
sum ln_conv if treatment_conv==3 
global y1_h5 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h5=`x'
count if treatment_conv==3 | treatment_conv==7
global n1_h5=`r(N)'

*Opp Message, Opp President - r3 *
global coeff1_h6="-0.0048" 
global p1_h6="0.4067"
global star1_h6 ""
sum ln_conv if treatment_conv==2 
global y1_h6 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h6=`x'
count if treatment_conv==2 | treatment_conv==6
global n1_h6=`r(N)'

restore


********************************************************************************
************************ AnonymousMessage **************************************

preserve

*generating outcome
gen ln_conv_align = ln1_prob_index_pro if  (treatment== 0 |  treatment== 3 |  treatment== 4 ) &  recruit==1
replace ln_conv_align = ln1_prob_index_anti if  (treatment== 0 |  treatment== 7 |  treatment== 8 ) &  recruit==0

gen ln_conv_against = ln1_prob_index_anti if  (treatment== 0 |  treatment== 7 |  treatment== 8 ) &  recruit==1
replace ln_conv_against = ln1_prob_index_pro if  (treatment== 0 |  treatment== 3 |  treatment== 4 ) &  recruit==0

* generating treatments
gen control 		= (treatment == 0)
gen actor_align 	= ((treatment == 3 | treatment == 4) & recruit == 1) ///
					| ((treatment == 7 | treatment == 8) & recruit == 0)
gen actor_against 	= ((treatment == 3 | treatment == 4) & recruit == 0) ///
					| ((treatment == 7 | treatment == 8) & recruit == 1) 

gen treatment_conv = control + 2*actor_align + 3*actor_against
replace treatment_conv = . if treatment_conv == 0
replace treatment_conv = treatment_conv-1

drop if treatment_conv == .

* 1 = actor aligned, 2 = actor against

mata: conv_decomp2anon = (1,1,1\2,1,2)

if $run ==1 {
mhtexp2 ln_conv_align ln_conv_against, treatment(treatment_conv) bootstrap(3000) combo("pairwise") only("conv_decomp2anon") controls(`alllasso')
}

*Command Does Not Auto-save Estimates*
*Manually Enter as Globals*
*Use P-Values from Remark3_8 in paper*
*Aligned Message - r1 *
global coeff1_h1="0.0110" 
global p1_h1="0.0093"
global star1_h1 "***"
sum ln_conv_align if treatment_conv==0 
global y1_h1 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h1=`x'
count if treatment_conv==0 | treatment_conv==1
global n1_h1=`r(N)'

*Opp Message - r2 *
global coeff1_h2="0.0173"
global p1_h2="0.0003"
global star1_h2 "***"
sum ln_conv_against if treatment_conv==0 
global y1_h2 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y1_h2=`x'
count if treatment_conv==0 | treatment_conv==2
global n1_h2=`r(N)'

restore


********************************************************************************
********************************Identified Message******************************

preserve

*generating outcome
gen ln_conv1= ln1_prob_index_anti if  ( treatment== 6 |  treatment== 10 )
replace ln_conv1= ln1_prob_index_pro if  (treatment== 1 |  treatment== 9 )

gen ln_conv2= ln1_prob_index_pro if  ( treatment== 2 |  treatment== 10)
replace ln_conv2= ln1_prob_index_anti if  (treatment== 5 |  treatment== 9 )

* gen treatments
gen ownpresident_against = ((treatment==6 &  recruit==1)  |  (treatment==1 &  recruit==0)) 
gen ownpresident_align = ((( treatment==2) &  recruit==1)  |  (( treatment==5) &  recruit==0)) 
gen ownturkey = ((( treatment==10) &  recruit==1)  |  (( treatment==9) &  recruit==0)) 

gen opppresident_against = ((( treatment==6) &  recruit==0)  |  (( treatment==1) &  recruit==1)) 
gen opppresident_align = ((( treatment==2) &  recruit==0)  |  (( treatment==5) &  recruit==1)) 
gen oppturkey = ((( treatment==10) &  recruit==0)  |  (( treatment==9) &  recruit==1))   

gen treatment_conv = ownturkey + 2*oppturkey + 3*ownpresident_against + 4*opppresident_against + 5*ownpresident_align + 6*opppresident_align
replace treatment_conv = . if treatment_conv == 0
replace treatment_conv = treatment_conv-1

drop if treatment_conv == .

* 0 = own turkey, 1 = opp turkey, 
* 2 = opp message by own president, 3 = opp message by opp president,
* 4 = aligned message by own president, 5 = aligned message by opp president

* we want to compare:
* outcome 1: 0 vs 2 - (2nd pairwise combination)
* outcome 1: 1 vs 3 - (7th)
* outcome 2: 0 vs 4 - (4th)
* outcome 2: 1 vs 5 - (9th)

mata: conv_decomp1idmessage = (1,1,2\1,1,7\2,1,4\2,1,9)

if $run ==1 {
mhtexp2 ln_conv1 ln_conv2, treatment(treatment_conv) bootstrap(3000) combo("pairwise") only("conv_decomp1idmessage") controls(`alllasso')
}

*Command Does Not Auto-save Estimates*
*Manually Enter as Globals*
*Use P-Values from Remark3_8 in paper*
*Own Message, Own President - r3 *
global coeff2_h3="0.0096"
global p2_h3="0.0973"
global star2_h3 "*"
sum ln_conv2 if treatment_conv==0 
global y2_h3 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h3=`x'
count if treatment_conv==0 | treatment_conv==4
global n2_h3=`r(N)'

*Opp Message, Own President - r1 *
global coeff2_h4="0.0344"
global p2_h4="0.0003"
global star2_h4 "***"
sum ln_conv1 if treatment_conv==0 
global y2_h4 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h4=`x'
count if treatment_conv==0 | treatment_conv==2
global n2_h4=`r(N)'


*Own Message, Opp President - r4 *
global coeff2_h5="0.0150"
global p2_h5="0.0230"
global star2_h5 "**"
sum ln_conv2 if treatment_conv==1 
global y2_h5 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h5=`x'
count if treatment_conv==1 | treatment_conv==5
global n2_h5=`r(N)'

*Opp Message, Opp President - r2 *
global coeff2_h6="-0.0035" 
global p2_h6="0.474"
global star2_h6 ""
sum ln_conv1 if treatment_conv==1 
global y2_h6 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h6=`x'
count if treatment_conv==1 | treatment_conv==3
global n2_h6=`r(N)'

restore


********************************************************************************
************************ Priming **************************************

preserve

*generating outcome
*generating outcome
gen ln_conv=ln1_prob_index_pro if recruit==1
replace ln_conv=ln1_prob_index_anti if recruit==0
replace ln_conv=. if treat>0 & treat<9

* generating outcomes
/*
gen ln_conv_align = ln1_prob_index_pro if  (treatment== 0 |  treatment== 3 |  treatment== 4 ) &  recruit==1
replace ln_conv_align = ln1_prob_index_anti if  (treatment== 0 |  treatment== 7 |  treatment== 8 ) &  recruit==0

gen ln_conv_against = ln1_prob_index_anti if  (treatment== 0 |  treatment== 7 |  treatment== 8 ) &  recruit==1
replace ln_conv_against = -ln1_prob_index_pro if  (treatment== 0 |  treatment== 3 |  treatment== 4 ) &  recruit==0
*/

* generating treatments
gen control 		= (treatment == 0)
gen ownpresident 	= (treatment == 10 & recruit == 1) ///
					| (treatment == 9 & recruit == 0)
gen opppresident 	= (treatment == 9 & recruit == 1) ///
					| (treatment == 10 & recruit == 0)

gen treatment_conv = control + 2*ownpresident + 3*opppresident
replace treatment_conv = . if treatment_conv == 0
replace treatment_conv = treatment_conv-1

drop if treatment_conv == .

* 1 = pres aligned, 2 = pres against

*mata: conv_decomp2anon = (1,1,1\1,1,2)

if $run ==1 {
mhtexp2 ln_conv, treatment(treatment_conv) bootstrap(3000) combo("treatmentcontrol") controls(`alllasso')
}

*Command Does Not Auto-save Estimates*
*Manually Enter as Globals*
*Use P-Values from Remark3_8 in paper*
*Own Leader - r1 *
global coeff2_h1="-0.0009"
global p2_h1="0.8470"
global star2_h1 ""
sum ln_conv if treatment_conv==0 
global y2_h1 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h1=`x'
count if treatment_conv==0 | treatment_conv==1
global n2_h1=`r(N)'

*Opp Leader - r2 *
global coeff2_h2="0.0028"
global p2_h2="0.7870"
global star2_h2 ""
sum ln_conv if treatment_conv==0 
global y2_h2 = round(`r(mean)'*1000)/1000
*local x = round(`r(mean)'*1000)/1000
*local x : di %6.3f `x'
*global y2_h2=`x'
count if treatment_conv==0 | treatment_conv==2
global n2_h2=`r(N)'

restore

log close



****************************************
****************************************
****************************************
*TABLE FOR OUTPUT*
****************************************
****************************************
****************************************

global y1_h4=".300"

foreach y in 1 3 4 5 {
	global space`y' "[0.1em]" 
	} 
foreach y in 2 {
	global space`y' "[1em]" 
	} 
foreach y in 6 {
	global space`y' "[1.1em]" 
	} 

global H1 "Message with Prior"
global H2 "Message against Prior"	
global H3 "Own Leader | Message with Prior"	
global H4 "Own Leader | Message against Prior"	
global H5 "Opposition Leader | Message with Prior"	
global H6 "Opposition Leader | Message against Prior"	

file close _all
capture macro drop fh
file open fh using "${out}A2_MultipleHypothesisTesting.tex", write replace
file write fh ///
"\hspace*{-1cm}\small{\begin{tabular}{lccccc}"  _n ///
"\toprule" _n ///
"\textbf{Persuasion Decomposition} & & & &    \\  " _n ///
"\textit{Outcome: ln(Prob(Convinced)+1)} & $\beta$ & Adj. P-Value & Y-Mean & N   \\  " _n ///
"\midrule \\" _n	///
"\textbf{A. Anonymous Message, $\beta_{m}$} &&&& \\ [0.5em]" _n 

foreach h in 1 2 {
file write fh ///
"${H`h'} & ${coeff1_h`h'}${star1_h`h'} & ${p1_h`h'} & 0${y1_h`h'} & ${n1_h`h'} \\" _n ///
"${space`h'}" _n	
}

file write fh ///
"\textbf{B. Persuasion, $\beta_{ms}$} &&&& \\ [0.5em]" _n 

foreach h in 3 4 5 6 {
file write fh ///
"${H`h'} & ${coeff1_h`h'}${star1_h`h'} & ${p1_h`h'} & 0${y1_h`h'} & ${n1_h`h'} \\" _n ///
"${space`h'}" _n	
} 


global H1 "Own Leader"
global H2 "Opposition Leader"	
global H3 "Message with Prior | Own Leader"	
global H4 "Message against Prior | Own Leader"	
global H5 "Message with Prior | Opposition Leader"	
global H6 "Message against Prior | Opposition Leader"	

file write fh ///
"\midrule " _n	///
"\textbf{Alternative Decomposition for Priming} & & & &    \\  " _n ///
"\textit{Outcome: ln(Prob(Convinced)+1)} & $\beta$ & Adj. P-Value & Y-Mean & N   \\  " _n ///
"\midrule \\" _n	///
"\textbf{C. Priming, $\beta_{s}$} &&&& \\ [0.5em]" _n 

foreach h in 1 2 {
file write fh ///
"${H`h'} & ${coeff2_h`h'}${star2_h`h'} & ${p2_h`h'} & 0${y2_h`h'} & ${n2_h`h'} \\" _n ///
"${space`h'}" _n	
}

file write fh ///
"\textbf{D. Identified Message, $\beta_{sm}$} &&&& \\ [0.5em]" _n 

foreach h in 3 4 5 6 {
file write fh ///
"${H`h'} & ${coeff2_h`h'}${star2_h`h'} & ${p2_h`h'} & 0${y2_h`h'} & ${n2_h`h'} \\" _n ///
"${space`h'}" _n	
} 


file write fh ///
"\bottomrule" _n ///
"\end{tabular}}\hspace*{-1cm}" _n
file close fh
